home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / NEXT_WDE / SOURCE / TESTER_S / TEST_COD.C
C/C++ Source or Header  |  1991-05-10  |  4KB  |  189 lines

  1. /*
  2.  * NeXT WDEF testing code
  3.  */
  4.  
  5. #include <MacTypes.h>
  6. #include <ColorToolbox.h>
  7.  
  8. #define testing
  9. #ifdef testing
  10. #define nil 0
  11. #endif testing
  12.  
  13. typedef struct {
  14.     int        jump;
  15.     long    add;
  16. } defRec, *defPtr, **defHdl;
  17.  
  18. defHdl        theDef;
  19. EventRecord    event;
  20. Boolean        hasQuit = false;
  21.  
  22. main()
  23. {
  24.     Boolean        gotEvent;
  25.     WindowPtr    window;
  26.     int            i;
  27.     Handle        menuBar;
  28.     Rect        wRect;
  29.     pascal long nextWDEF(/* variation, window, message, parameter */);
  30.  
  31.     InitGraf(&thePort);
  32.     InitCursor();
  33.     InitFonts();
  34.     InitWindows();
  35.     InitMenus();
  36.     TEInit();
  37.     InitDialogs(nil);
  38.  
  39.     MoreMasters();
  40.     MoreMasters();
  41.     
  42.     FlushEvents(everyEvent, 0);    /* flush toilet */
  43.     GetNextEvent(everyEvent, &event);
  44.     GetNextEvent(everyEvent, &event);
  45.     
  46.     theDef = (defHdl)GetResource('WDEF', 10);
  47.     (**theDef).jump = 0x4ef9;
  48.     (**theDef).add = (long)nextWDEF;
  49.     
  50.     menuBar = GetNewMBar(128);
  51.     SetMenuBar(menuBar);
  52.     DisposHandle(menuBar);
  53.     AddResMenu(GetMHandle(128), 'DRVR');
  54.     DrawMenuBar();
  55.     
  56.     SetRect(&wRect, 20, 60, 420, 260);
  57.     window = NewWindow((WindowPeek)nil, &wRect, "\pThis is obviously a very nice window.", true, 168, (WindowPeek)-1l, true, 0);
  58.     OffsetRect(&wRect, 40, 40);
  59.     window = NewCWindow((WindowPeek)nil, &wRect, "\pThe 2nd window!", true, 168, (WindowPeek)-1l, true, 0);
  60.     
  61.     do {
  62.         SystemTask();
  63.         gotEvent = GetNextEvent(everyEvent, &event);
  64.         
  65.         if (gotEvent) {
  66.             switch(event.what) {
  67.             case mouseDown:
  68.                 DoMouseDown();
  69.                 break;
  70.             case updateEvt:
  71.                 DoUpdate((WindowPtr) event.message);
  72.                 break;
  73.             }
  74.         }
  75.     } while(!hasQuit);
  76. }
  77.  
  78. DoMouseDown()
  79. {
  80.     short        part;
  81.     WindowPtr    window;
  82.     long        growResult;
  83.     Rect        growRect;
  84.     
  85.     part = FindWindow(event.where, &window);
  86.     switch (part) {
  87.     case inMenuBar:
  88.         doMenu(MenuSelect(event.where));
  89.         break;
  90.     case inDrag:
  91.         DragWindow(window, event.where, &screenBits.bounds);
  92.         break;
  93.     case inContent:
  94.         if ( window != FrontWindow() )
  95.             SelectWindow(window);
  96.     case inGoAway:
  97.         SetPort(window);
  98.         if ( TrackGoAway(window, event.where) )
  99.             hasQuit = true;
  100.         break;
  101.     case inGrow:
  102.         SetPort(window);
  103.         SetRect(&growRect, 80, 60, 600, 500);
  104.         growResult = GrowWindow(window, event.where, &growRect);
  105.         if (growResult != 0)
  106.             SizeWindow(window, LoWord(growResult), HiWord(growResult), true);
  107.         break;
  108.     case inZoomIn:
  109.     case inZoomOut:
  110.         SetPort(window);
  111.         if ( TrackBox(window, event.where, part) ) {
  112.             EraseRect(&thePort->portRect);
  113.             ZoomWindow(window, part, window == FrontWindow());
  114.             InvalRect(&thePort->portRect);
  115.         }
  116.         break;
  117.     }
  118. }
  119.  
  120. doMenu(mChoice)
  121. long    mChoice;
  122. {
  123.     int            menuID, menuItem;
  124.     WindowPtr    window;
  125.     Rect        wRect;
  126.     Boolean        goAwayIcon;
  127.     
  128.     menuID = HiWord(mChoice);
  129.     menuItem = LoWord(mChoice);
  130.     window = FrontWindow();
  131.     
  132.     if (menuID == 129)
  133.         switch(menuItem) {
  134.         case 1: 
  135.             DisposeWindow(window);
  136.             SetRect(&wRect, 60, 60, 360, 300);
  137.             goAwayIcon = true;
  138.             window = NewWindow(nil, &wRect, "\pChanged.", true, menuItem-1, (WindowPtr)-1l, goAwayIcon, 0l);
  139.             break;
  140.         case 2: case 3: case 4: case 5:
  141.             DisposeWindow(window);
  142.             SetRect(&wRect, 60, 60, 360, 300);
  143.             goAwayIcon = true;
  144.             window = NewWindow(nil, &wRect, "\pChanged.", false, menuItem-1, (WindowPtr)-1l, goAwayIcon, 0l);
  145.             break;
  146.         case 6:
  147.             DisposeWindow(window);
  148.             SetRect(&wRect, 70, 70, 360, 300);
  149.             goAwayIcon = true;
  150.             window = NewWindow(nil, &wRect, "\pBack again.", true, 12, (WindowPtr)-1l, goAwayIcon, 0l);
  151.             break;
  152.         case 7:
  153.             DisposeWindow(window);
  154.             SetRect(&wRect, 70, 70, 360, 300);
  155.             goAwayIcon = false;
  156.             window = NewWindow(nil, &wRect, "\pBack again.", true, 12, (WindowPtr)-1l, goAwayIcon, 0l);
  157.             break;
  158.         case 8:
  159.             DisposeWindow(window);
  160.             SetRect(&wRect, 70, 70, 360, 300);
  161.             goAwayIcon = true;
  162.             window = NewWindow(nil, &wRect, "\pBack again.", true, 8, (WindowPtr)-1l, goAwayIcon, 0l);
  163.             break;
  164.         case 10:
  165.             hasQuit = true;
  166.             break;
  167.     }
  168.     HiliteMenu(0);
  169. }
  170.  
  171. DoUpdate(window)
  172. WindowPtr    window;
  173. {
  174.     Rect    box;
  175.     
  176.     SetPort(window);
  177.     BeginUpdate(window);
  178.     if ( ! EmptyRgn(window->clipRgn) ) {
  179.         PenNormal();
  180.         EraseRgn(window->clipRgn);
  181.         SetRect(&box, 10, 10, 200, 200);
  182.         FillOval(&box, <Gray);
  183.         OffsetRect(&box, 10, -10);
  184.         FillOval(&box, &gray);
  185.         if (((*(WindowPeek)window).windowKind = 0) || ((*(WindowPeek)window).windowKind = 8)) drawGrowIcon( 0, window, 0 );
  186.     }
  187.     EndUpdate(window);
  188. }
  189.